Skip to content

add simple form and loading state#7

Merged
JasonDebnath001 merged 2 commits into
mainfrom
fix/addSimpleForm
May 16, 2026
Merged

add simple form and loading state#7
JasonDebnath001 merged 2 commits into
mainfrom
fix/addSimpleForm

Conversation

@JasonDebnath001

@JasonDebnath001 JasonDebnath001 commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

Release Notes

  • New Features

    • Added two prompt builder modes: "Guided" (structured multi-field form) and "Simple" (single description textarea) with mode toggle on home page
    • Added loading state UI with visual feedback on the build page
  • Bug Fixes

    • Improved error handling and response parsing for prompt generation
  • UI Updates

    • Reorganized home page layout with mode selection interface
    • Refreshed build page interface and styling

Review Change Stack

@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
prompt-forge Ready Ready Preview, Comment May 16, 2026 3:50pm

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@JasonDebnath001 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 44 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f2df51ac-9629-4120-ae7d-66d65532e8d0

📥 Commits

Reviewing files that changed from the base of the PR and between 96f6b74 and 21e627c.

📒 Files selected for processing (2)
  • app/build/page.tsx
  • app/page.tsx
📝 Walkthrough

Walkthrough

This PR introduces guided and simple modes for the prompt-generation flow. The home page now offers two input paths: guided (structured multi-field form) or simple (single-textarea description). The API endpoint distinguishes mode during brief processing and Gemini prompt construction, while the build page refactors its layout to support loading states and displays responses in a new themed card structure.

Changes

Guided & Simple Mode Support

Layer / File(s) Summary
Mode Schema & Initial State
app/api/generate-prompt/route.ts, app/page.tsx
Brief type extended with mode?: "guided" | "simple" and optional description. HomePage gains Mode and GuidedFormState types; INITIAL_GUIDED_STATE constant replaces single FormState.
Brief Processing & Prompt Construction
app/api/generate-prompt/route.ts
buildBrief detects simple mode with description and returns early; description added to brief output with fallback message. POST handler derives isSimple flag and conditionally switches Gemini prompt instructions between plain-language and following-brief variants.
Gemini Response Handling
app/api/generate-prompt/route.ts
Error responses parse JSON or fall back to raw text with upstream status; success parsing extracts first candidate/part and returns 502 if empty; simplified outer catch removes timeout specialization.
Home Page: Mode Selection & Input Collection
app/page.tsx
buildQueryParams now mode-aware: simple mode uses description-only, guided mode uses multi-field form. HomePage state refactored to track mode, guidedForm, description separately; validation logic per mode. UI adds mode toggle buttons, conditionally renders textarea (simple) or field grid (guided), updates info panel copy to distinguish guided vs. simple framing.
Build Page: Response Display & Loading State
app/build/page.tsx, app/build/loading.tsx
readBrief extracts mode and trimmed description from query params; GeneratePromptResponse type added. BuildPageContent refactored with Navbar moved inside, removes brief-card iteration, applies new themed layout. New Loading component renders Navbar plus animated skeleton with Sparkles labels.

Sequence Diagram

sequenceDiagram
  participant User
  participant HomePage as Home Page
  participant API as /api/generate-prompt
  participant Gemini as Gemini API
  participant BuildPage as Build Page

  User->>HomePage: Select mode (guided or simple)
  alt Guided Mode
    User->>HomePage: Fill context, skills, format fields
  else Simple Mode
    User->>HomePage: Enter description
  end
  
  User->>HomePage: Submit
  HomePage->>HomePage: Validate inputs per mode
  HomePage->>HomePage: buildQueryParams (mode-aware)
  HomePage->>BuildPage: Navigate /build?params
  BuildPage->>BuildPage: Show Loading (Navbar + Forging skeleton)
  BuildPage->>API: POST request with Brief (mode, description)
  
  API->>API: Validate body → create Brief
  API->>API: isSimple = (mode='simple' OR description present)
  API->>API: buildBrief (simple early-return, include description)
  API->>API: Construct Gemini prompt (conditional instruction text)
  API->>Gemini: Send prompt request
  Gemini->>API: Return response with content
  
  API->>API: Parse first candidate text
  API->>BuildPage: Return GeneratePromptResponse (prompt text)
  
  BuildPage->>BuildPage: Parse response JSON
  BuildPage->>BuildPage: Display prompt in themed layout
  User->>BuildPage: Copy prompt
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • JasonDebnath001/PromptForge#4: Introduces the initial /api/generate-prompt route and request/response shape; this PR extends it with mode-aware brief logic and simplified error handling.
  • JasonDebnath001/PromptForge#6: Directly modifies app/api/generate-prompt/route.ts to structure the Brief/buildBrief flow and Gemini request/response handling that this PR builds upon.
  • JasonDebnath001/PromptForge#2: Introduces the build page UI; this PR refactors the same page's brief parsing, layout, and JSON response typing.

Poem

🐰 Two paths through the forge, now bright,
Guided fields or simple light—
Brief flows swift through Gemini's care,
Loading sparks dance in the air.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add simple form and loading state' directly matches the main changes: a new simple form mode added to app/page.tsx and a new loading state component added via app/build/loading.tsx.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/addSimpleForm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/api/generate-prompt/route.ts`:
- Around line 164-174: The current code only uses the first Gemini content part
(parsed?.candidates?.[0]?.content?.parts?.[0]?.text) which can truncate outputs;
update the logic that constructs promptText (and uses cleanText) to concatenate
all parts' text for the first candidate by iterating
parsed?.candidates?.[0]?.content?.parts, extracting each part.text (ignoring
undefined), joining them into a single string, then pass that concatenated
string to cleanText so the full Gemini response is preserved; keep references to
parsed, promptText, cleanText and the content.parts array when making the
change.

In `@app/page.tsx`:
- Around line 91-97: Avoid putting long free-form textarea content into the URL:
in the branch that checks mode === "simple" (the code that trims description and
calls params.set("description", trimmed)), validate and enforce a maximum length
(e.g., <= 2000 chars) before adding description to params; if the trimmed
description exceeds the limit, instead persist it via client storage
(sessionStorage/localStorage) or a short server-side token and set a short
flag/query param (e.g., description_stored=true or description_token=<id>) so
/build can retrieve the full text, and apply the same guard/alternate-storage
approach to the other occurrence that sets description in params (the lines
around the second params.set("description")).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a67aa986-484c-4b4f-94be-f9cfd11376a9

📥 Commits

Reviewing files that changed from the base of the PR and between 9916189 and 96f6b74.

📒 Files selected for processing (4)
  • app/api/generate-prompt/route.ts
  • app/build/loading.tsx
  • app/build/page.tsx
  • app/page.tsx

Comment on lines +164 to +174
const parsed = JSON.parse(rawText) as {
candidates?: Array<{
content?: { parts?: Array<{ text?: string }> };
content?: {
parts?: Array<{ text?: string }>;
};
}>;
} | null = null;
};

try {
data = JSON.parse(rawText);
} catch (parseError) {
console.error("Failed to parse Gemini response", {
error: parseError,
rawText,
});
const promptText = cleanText(
parsed?.candidates?.[0]?.content?.parts?.[0]?.text || "",
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In the Gemini generateContent API response schema, can candidates[0].content.parts contain multiple text parts for one candidate, and should clients concatenate them to reconstruct the full text response?

💡 Result:

Yes, the Gemini generateContent API response schema can contain multiple text parts within candidates.content.parts [1][2][3]. While many simple requests return a single text part, the API may return multiple parts in scenarios such as when the model includes "thinking" blocks, function calls, or other structured content alongside the generated text [2][3]. Clients should not rely solely on convenience accessors (like response.text) if they need to handle all response types robustly, as these accessors often only work for simple, single-part responses and may fail or return incomplete data when multiple parts are present [4][5][6]. To reconstruct the full text response correctly, clients should iterate through the parts array, check for the presence of text, and concatenate all text segments [4][2][3]. Example logic for reconstruction: const fullText = response.candidates.content.parts.filter(part => part.text).map(part => part.text).join(''); [4][2]

Citations:


🏁 Script executed:

cat -n app/api/generate-prompt/route.ts | sed -n '160,180p'

Repository: JasonDebnath001/PromptForge

Length of output: 686


🏁 Script executed:

cat -n app/api/generate-prompt/route.ts | sed -n '150,190p'

Repository: JasonDebnath001/PromptForge

Length of output: 1295


Concatenate all returned Gemini text parts instead of reading only the first part.

At lines 172–174, the code uses only parts[0]?.text, which can truncate valid output when the Gemini API response splits content across multiple parts. The API may return multiple text parts in the content.parts array—for example, when the model includes thinking blocks or other structured content—and clients should concatenate all text segments to reconstruct the full response.

Proposed fix
-    const promptText = cleanText(
-      parsed?.candidates?.[0]?.content?.parts?.[0]?.text || "",
-    );
+    const promptText = cleanText(
+      (parsed?.candidates?.[0]?.content?.parts ?? [])
+        .map((part) => part?.text ?? "")
+        .join(""),
+    );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/api/generate-prompt/route.ts` around lines 164 - 174, The current code
only uses the first Gemini content part
(parsed?.candidates?.[0]?.content?.parts?.[0]?.text) which can truncate outputs;
update the logic that constructs promptText (and uses cleanText) to concatenate
all parts' text for the first candidate by iterating
parsed?.candidates?.[0]?.content?.parts, extracting each part.text (ignoring
undefined), joining them into a single string, then pass that concatenated
string to cleanText so the full Gemini response is preserved; keep references to
parsed, promptText, cleanText and the content.parts array when making the
change.

Comment thread app/page.tsx
@JasonDebnath001 JasonDebnath001 merged commit 226e42d into main May 16, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant